<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
  <div id="app">
    <h2>添加</h2>
    <input type="text" @keydown.enter="addList" v-model="addValue">
    <h3>搜索</h3>
    <input type="text" v-model="searchValue">
    <ul>
      <!-- 渲染计算属性 搜索的列表 -->
      <li v-for="(v, i) in searchList" :key="v.id">
        <b>{{ v.id }}</b>
        <span>{{ v.con }}</span>
        <span>{{ v.isChecked }}</span>
        <input type="checkbox" v-model="v.isChecked">
        <b @click="deleteList(v.id)">删除</b>
      </li>
    </ul>
  </div>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        list: [{
          id: Math.random().toString().slice(2),
          con: "睡觉",
          isChecked: true
        },
        {
          id: Math.random().toString().slice(2),
          con: "学习",
          isChecked: false
        }],
        addValue: '',
        searchValue: ''
      },
      methods: {
        deleteList(id) {
          // 过滤 id
          this.list = this.list.filter(item => item.id !== id)
        },
        addList() {
          this.list.push({
            id: Math.random().toString().slice(2),
            con: this.addValue,
            isChecked: false
          })

          this.addValue = ''
        }
      },
      computed: {
        // 搜索的列表
        searchList() {
          return this.list.filter(item => item.con.includes(this.searchValue))
        }
      }
    })
  </script>
</body>

</html>